#pragma once
#include"Hash.h"

namespace Unordered_map {
template<class K,class V>
class KeyOfT {
public:
	const K& operator()(const pair<K,V>& kv) {
		return kv.first;
	}
};

template<class K,class V>
class unordered_map {
protected:
	HashTable<K, pair<const K, V>, KeyOfT<K,V>> _ht;

public:
	typedef typename HashTable<K, pair<const K, V>, KeyOfT<K, V>>::iterator iterator;
	typedef typename HashTable<K, pair<const K, V>, KeyOfT<K, V>>::const_iterator const_iterator;

	pair<iterator,bool> Insert(const pair< K,V>& kv) {
		return _ht.Insert(kv);
	}

	bool Erase(const pair<K,V>& kv) {
		return _ht.Erase(kv);
	}

	iterator begin() {
		return _ht.begin();
	}

	const_iterator begin()const {
		return _ht.begin();
	}

	iterator end() {
		return _ht.end();
	}

	const_iterator end()const {
		return _ht.end();
	}

	V& operator[](const K& key) {
		pair<iterator, bool> ret = _ht.Insert(make_pair(key,V()));
		return ret.first->second;
	}
};

}